#include "StdAfx.h"
#include "DrawRadialGrads.h"


CDrawRadialGrads::CDrawRadialGrads(void)
{
}


CDrawRadialGrads::~CDrawRadialGrads(void)
{
}
BEGIN_MESSAGE_MAP(CDrawRadialGrads, CDrawOpenCV)
	ON_WM_PAINT()
END_MESSAGE_MAP()



void CDrawRadialGrads::DealwithFrame()
{
	// TODO: Add your command handler code here
	if(m_pFrame == NULL)
	{			
		return ;
	}
	if(m_pShow != NULL)
	{
		cvReleaseImage(&m_pShow);
	}
	m_pShow= (IplImage *)cvClone(m_pFrame);
	CvPoint center;
	double  scale = -3;

	center = cvPoint(m_pShow->width/2,m_pShow->height/2);

	for (int i=0; i<m_pShow->height; i++) {
		for (int j=0; j<m_pShow->width; j++) {
			double dx=(double)(j-center.x)/center.x;
			double dy=(double)(i-center.y)/center.y;
			double weight=exp((dx*dx+dy*dy)*scale);
			uchar *ptr = &CV_IMAGE_ELEM(m_pShow,uchar,i,j*3);
			ptr[0]=cvRound(ptr[0]*weight);
			ptr[1]=cvRound(ptr[1]*weight);
			ptr[2]=cvRound(ptr[2]*weight);
		}
	}

}
